<?php
    include 'db.php';

    $sessionid=$_GET['s'];
    $starttime = 0;
    $endtime = 0;
    $q=mysql_query("SELECT `timestamp` FROM messages WHERE `sessionid`=7 ORDER BY `timestamp` ASC LIMIT 1");

    while($data = mysql_fetch_row($q)){
        $starttime = $data[0];
    }

    $r=mysql_query("SELECT `timestamp` FROM messages WHERE `sessionid`=7 ORDER BY `timestamp` DESC LIMIT 1");
    while($data = mysql_fetch_row($r)){
        $endtime = $data[0];
    }

    echo $starttime .PHP_EOL;
    echo $endtime .PHP_EOL;
    echo round(abs(strtotime($endtime) - strtotime($starttime))/60,0);

    mysql_close($link);
?>
